import Compiler from "./Compiler";
import {observe} from "./observe";
import Watcher from "./Watcher";
export  default class Vue {
  constructor(options) {
    this.$options = options || {}
    this._data = options.data || undefined
    observe(this._data)
    this._initData();
    this._initComputed();
    // 数据变为响应式
    this._initWatch()
    // 模板编译
    new Compiler(options.el,this)
  }
  _initData(){
    var self = this
    Object.keys(this._data).forEach(key =>{
      Object.defineProperty(self,key,{
        get(){
          return self._data[key]
        },
        set(v) {
          self._data[key] = v
        }
      })
    })
  }
  _initComputed(){

  }
  _initWatch(){
    var self = this;
    var watch = this.$options.watch;
    Object.keys(watch).forEach(key =>{
      new Watcher(self,key,watch[key])
    })
  }
}